{% extends "ponsol2web/base_generic.html" %}
{% load my_filter %}
{% block title %} Detail {% endblock %}

{% block content_title %} Result Detail{% endblock %}
{% block content %}

    <div class="page-header">
        <h1>Prediction Result</h1>
    </div>
    <div class="panel panel-default">
        <!-- Default panel contents -->
        <div class="panel-heading">Task Information</div>
        <div class="panel-body">
            <div style="">
                {% if task.status == "running" %}
                    <div class="" role="alert">
                        <strong>Running!</strong> This task(id={{ task.id }}) is running now, please wait a moment.
                        {% if task.mail %}
                            The result will be sent to
                            <ins>{{ task.mail }}</ins>.
                        {% endif %}
                    </div>
                {% elif task.status == "finished" %}
                    <div class="" role="alert"><strong>Finished!</strong> This task(id={{ task.id }}) is finished,
                        the results are as follows.
                        {% if task.mail %}
                            The results are also sent as e-mail to
                            <ins>{{ task.mail }}</ins>.
                        {% endif %}
{#                        Running time is from {{ task.start_time }} to {{ task.finish_time }}#}
                    </div>
                {% elif task.status == "error" %}
                    <div class="" role="alert"><strong>Error!</strong> {{ task.error_msg }}</div>            {% endif %}
            </div>
        </div>
    </div>
    <div>

        {# 分组数据 #}
        {% if record_group %}
            {% for record_list in record_group %}
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        Protein {{ forloop.counter }}:
                        {% if record_list.0.seq_id %}
                            {{ record_list.0.get_seq_id_type_display }} is {{ record_list.0.seq_id }}
                        {% else %}
                            No ID provided
                        {% endif %}
                    </div>
                    <div class="panel-body">
                        <p>
                            Protein name: {{ record_list.0.name | shorten_str }};
                            Protein sequence: {{ record_list.0.seq | shorten_str }};
                            <a class="" href="{% url "ponsol2:protein_detail" record_list.0.id %}">more</a>
                        </p>
                    </div>
                    <table class="table">
                        <tr class="row">
                            <th class="col-md-1">#</th>
                            <th class="col-md-3 ">Variation</th>
                            <th class="col-md-3 ">Prediction result</th>
                            <th class="col-md-5 ">Remark</th>
                        </tr>
                        {% for record in record_list %}
                            <tr class="row">

                                <td> {{ forloop.counter }}</td>
                                <td>
                                    <a href="{% url "ponsol2:record-detail" record.id %}"> {{ record.aa }}</a>
                                </td>
                                <td>
                                    {% if record.solubility %}
                                        {{ record.get_solubility_display }}
                                        {#                                        {% elif record.status %}#}
                                    {% else %}
                                        <span class="text-danger">
                                                {{ record.status }}
                                        </span>
                                    {% endif %}
                                </td>
                                <td>
                                    {% if record.error_msg %}
                                        {{ record.error_msg }}
                                    {% else %}
                                        -
                                    {% endif %}
                                    {#                                    <a href="{% url "ponsol2:record-detail" record.id %}"> see details</a>#}
                                </td>
                            </tr>
                        {% endfor %}
                    </table>
                </div>
            {% endfor %}
        {% endif %}
    </div>
    <div>
        <ul class="nav nav-list">
            <li class="divider"></li>
        </ul>
        <h5 class="page-header"></h5>
        <div>
            <br>
            <p>
                If you find that there is no result or some variation have been missed, it is usually due to an incorrect
                input format.
                Please check whether all variations can be matched to input FASTA sequence.
            </p>
        </div>
    </div>
    {% if task.status == "running" %}
        <script type="text/javascript">
            function myrefresh() {
                window.location.reload();
            }
            setTimeout("myrefresh()", 1000);
        </script>
    {% endif %}
{% endblock %}
